﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Xin478.CSWork.Common;

namespace Xin478.CSWork.Client
{
    public partial class RemindTipForm : MyForm
    {
        RemindInfo remindInfo;
        public event EventHandler SureButtonClick;
        public event EventHandler LaterButtonClick;

        public RemindTipForm()
        {
            InitializeComponent();
            this.Load += new EventHandler(RemindTipForm_Load);
        }
        public RemindTipForm(RemindInfo remindInfo)
        {
            InitializeComponent();
            this.remindInfo = remindInfo;
            this.Load += new EventHandler(RemindTipForm_Load);
        }
        void RemindTipForm_Load(object sender, EventArgs e)
        {
            textBox1.Text = this.remindInfo.Detail;
            label2.Text = remindInfo.AddTime.Value.ToString("yyyy年MM月dd日 HH:mm:ss");

            string t = remindInfo.DefiniteTime == -1 ? "首次登陆时" : " " + (remindInfo.DefiniteTime / 100).ToString() + ":" + (remindInfo.DefiniteTime % 100).ToString();

            if (!string.IsNullOrEmpty(remindInfo.DefiniteDate))
                label4.Text = remindInfo.DefiniteDate + t;
            else if (remindInfo.PlanType == 0)
                label4.Text = "每天" + t;
            else if (remindInfo.PlanType < 0)
            {
                label4.Text = "每周" + weekStr(-remindInfo.PlanType) + t;
            }
            else
                label4.Text = "每月" + remindInfo.PlanType.ToString() + "号" + t;
        }
        string weekStr(int d)
        {
            switch (d)
            {
                case 0: return "周日";
                case 1: return "周一";
                case 2: return "周二";
                case 3: return "周三";
                case 4: return "周四";
                case 5: return "周五";
                case 6: return "周六";
            }
            return "";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (LaterButtonClick != null) LaterButtonClick(remindInfo, e);
            CloseMe();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (SureButtonClick != null) SureButtonClick(remindInfo, e);
            CloseMe();
        }

        void CloseMe()
        {
            TipList.Instance.Remove(new RemindTipItem(remindInfo,null));
            this.Close();
            this.Dispose();
        }

    }
}
